#include "motor.h"
#include "pwm.h"
#include "config.h"

extern uint32_t motor_speed;

motor_t motors[MOTOR_COUNT];

/**
 * set motor speed
 *
 * @param  uint32_t value channel duty (0 - 1000)
 * @param  uint8_t motor (1-6)
 * @return status
 *
 * @brief  change motor speed
 *
 */
uint32_t motor_set_speed(motor_t *motor)
{
    /* add base frequency */
    return pwm_set(motor->speed, motor->number);
}

/**
 * get motor speed
 *
 * @param  uint32_t value channel duty (0 - 1000)
 * @param  uint8_t motor (1-6)
 * @return status
 *
 * @brief  change motor speed
 *
 */
uint32_t motor_get_speed(motor_t *motor)
{
    return pwm_get_duty(&motor->speed, motor->number);
}

/**
 * set motor speed to 0
 *
 * @param  uint8_t motor (1-6)
 * @return status
 *
 * @brief  change motor speed to 0
 *
 */
uint32_t motor_switch_off(motor_t *motor)
{
    motor->speed = 96000;
    return pwm_set(motor->speed, motor->number);
}
